<?php
/*
 * 车主圈编辑
 * @arrange WL
 * @package ixdcw
 * @file    owners.inc.php
 * @time    12-12-19 上午11:01
 */

defined('IN_IXDCW') or exit('Access Denied');

login();

require DT_CORE.'/'.$module.'/common.inc.php';
require_once DT_INC.'/post.func.php';
isCompleteData();//检测个人资料是否完善

$do = new OwnersModule($moduleid);
$do->setUsername($_username);

switch($action) {
	case 'car':
		$item = $do->getOne();
		$mareaid = $db->getVar("select areaid from xd_member where username = '".$_username."'");
		$item['mareaname'] = $AREA[$mareaid]['areaname'];
		$item['arbid'] = explode(',',$item['arbid']);
		$item['arcid'] = explode(',',$item['arcid']);
		$item['amid'] = explode(',',$item['amid']);
		$item['bytime'] = explode(',',$item['bytime']);
		$bytime         = $item['bytime'];
		foreach($item['arbid'] as $k=>$v){
			$item['bytime'][$k+1] = $bytime[$k];
			if($k==0)unset($bytime[$k]);
			$item['brand'][$k+1] = AutoBrand::get($v);
			$item['car'][$k+1] = AutoCar::get($item['arcid'][$k]);
			$item['model'][$k+1] = AutoModel::get($item['amid'][$k]);
		}
	if($post) {
		if($do->pass($post)) {
			$do->edit($post);
			Prompt::tip('资料编辑成功', "?action=$action&mid=$mid");
		}else{
			Prompt::alert($do->getErrmsg(),"?action=$action&mid=$mid");
		}
	}
	break;
	case 'addcar':
		if($post) {
			if($do->pass($post)) {
				$do->addcar($post);
				Prompt::tip('车型添加成功', "?action=likecar&status=1&mid=$mid");
			}else{
				Prompt::alert($do->getErrmsg(),"?action=car&mid=$mid");
			}
		}
	break;
	case 'area':
		if($post) {
			if($do->passArea($post)) {
				$do->edit($post);
				Prompt::tip('资料编辑成功', "?action=car&mid=$mid");
			}else{
				Prompt::alert($do->getErrmsg(),"?action=car&mid=$mid");
			}
		}
		break;
	case 'editcar':
		$itemid or Prompt::message();
		$do->setItemid($itemid);
		$items = $do->getOne_likecar();
		if(!$items || $items['username'] != $_username) Prompt::message();
		if($post) {
			if($do->pass($post)) {
					$do->editcar($post);
					Prompt::tip('车型修改成功', "?action=likecar&status=1&mid=$mid");
				}else{
				    Prompt::alert($do->getErrmsg(),"?action=car&mid=$mid");
				}
		} else {
				extract($item);
			}
	break;
	case 'likecar':
		$lists = $do->getList_likecar('','addtime desc');
	break;
	case 'edit':
		$itemid or msg('请选择'.$MOD['name']);
		$do->editlove($itemid,$post);
		Prompt::tip('删除成功', $forward);
		break;
	case 'delcar':
		$itemid or Prompt::message('请选择'.$MOD['name']);
		 $do->delcar($itemid);
		Prompt::tip('删除成功', $forward);
		break;
	case 'delete':
		$itemid or msg('请选择'.$MOD['name']);
		$do->delete($itemid);
		Prompt::tip('删除成功', $forward);
		break;
	default:
		$item = $do->getOne();
		$mareaid = $db->getVar("select areaid from xd_member where username = '".$_username."'");
		$item['mareaname'] = area_pos($mareaid,'',0,'3421');
		$item['arbid'] = explode(',',$item['arbid']);
		$item['arcid'] = explode(',',$item['arcid']);
		$item['amid'] = explode(',',$item['amid']);
		$item['bytime'] = explode(',',$item['bytime']);
		foreach($item['arbid'] as $k=>$v){
			$item['brand'][$k+1] = AutoBrand::get($v);
			$item['car'][$k+1] = AutoCar::get($item['arcid'][$k]);
			$item['model'][$k+1] = AutoModel::get($item['amid'][$k]);
		}

}

include template('owners', 'member');
?>